﻿using Sidvall.Serialization;

namespace Sidvall.Net
{
    public class LanguageHeader
    {
        #region Public Members

        public string CultureName { get; set; }
        public double? Quality { get; set; }

        #region Copy

        public LanguageHeader Copy()
        {
            var item = new LanguageHeader()
            {
                CultureName = this.CultureName,
                Quality = this.Quality,
            };
            return item;
        }

        #endregion
        #region IsEqual

        public bool IsEqual(LanguageHeader obj)
        {
            return IsEqual(this, obj);
        }

        #endregion
        #region ToString

        public override string ToString()
        {
            if (string.IsNullOrWhiteSpace(this.CultureName))
                return string.Empty;
            if (this.Quality != null)
                return this.CultureName + ";q=" + this.Quality.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
            return this.CultureName;
        }

        #endregion

        #region IsEqual - Static

        public static bool IsEqual(LanguageHeader item1, LanguageHeader item2)
        {
            if (item1 == null)
            {
                if (item2 == null)
                    return true;
                else
                    return false;
            }
            else if (item2 == null)
                return false;
            if (!item1.CultureName.Equals(item2.CultureName, true, System.StringComparison.OrdinalIgnoreCase))
                return false;
            if (!(item1.Quality == item2.Quality))
                return false;
            return true;
        }

        #endregion

        #endregion
    }
}
